import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/**
 * ///GridView({
    Axis scrollDirection = Axis.vertical,
    bool reverse = false,
    ScrollController controller,
    bool primary,
    ScrollPhysics physics,
    bool shrinkWrap = false,
    EdgeInsetsGeometry padding,
    @required SliverGridDelegate gridDelegate, //控制子widget layout的委托

    SliverGridDelegateWithFixedCrossAxisCount({
    @required double crossAxisCount,  //横轴子元素的数量
    double mainAxisSpacing = 0.0,   //主轴方向的间距
    double crossAxisSpacing = 0.0, //横轴方向子元素的间距
    double childAspectRatio = 1.0, //子元素在横轴长度和主轴长度的比例
    })
    bool addAutomaticKeepAlives = true,
    bool addRepaintBoundaries = true,
    double cacheExtent,
    List<Widget> children = const <Widget>[],
    })
 */

///

class GridViewWidget extends StatefulWidget {
  final String? text;

  GridViewWidget({this.text}) : super();

  @override
  State<StatefulWidget> createState() {
    return _GrideState(text ?? "");
  }
}

class _GrideState extends State<GridViewWidget> {
  String? title;

  _GrideState(String text) {
    title = text;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title ?? ""),
      ),
      body: Container(
        padding: EdgeInsets.all(20),
        child: GridView(
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 3, //横轴三个子widget
              crossAxisSpacing: 20, //横轴方向子元素的间距
              mainAxisSpacing: 10, //主轴方向的间距
              childAspectRatio: 1.5 //宽高比为1时，子widget
              ),
          children: [
            DecoratedBox(
              decoration: BoxDecoration(color: Colors.black12),
              child: Icon(Icons.ac_unit),
            ),
            DecoratedBox(
              decoration: BoxDecoration(color: Colors.black12),
              child: Icon(Icons.airport_shuttle),
            ),
            DecoratedBox(
              decoration: BoxDecoration(color: Colors.black12),
              child: Icon(Icons.all_inclusive),
            ),
            DecoratedBox(
              decoration: BoxDecoration(color: Colors.black12),
              child: Icon(Icons.beach_access),
            ),
            DecoratedBox(
              decoration: BoxDecoration(color: Colors.black12),
              child: Icon(Icons.cake),
            ),
            DecoratedBox(
              decoration: BoxDecoration(color: Colors.black12),
              child: Icon(Icons.free_breakfast),
            ),
          ],
        ),
      ),
    );
  }
}
